package com.bw.lyc.mvp.presenter;


import com.bw.lyc.mvp.base.model.BaseEntity;
import com.bw.lyc.mvp.base.presenter.BasePresenter;
import com.bw.lyc.mvp.contract.LoginContract;
import com.bw.lyc.util.ToastUtils;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;

public class LoginPresenter extends BasePresenter<LoginContract.ILoginModel, LoginContract.ILoginView> {

    @Inject
    public LoginPresenter(LoginContract.ILoginModel iLoginModel, LoginContract.ILoginView iLoginView) {
        super(iLoginModel, iLoginView);
    }

    //声明对应请求方法
    //phone->当前用户登录的手机号
    //pwd->用户密码
    public void requestLogin(long phone,String pwd,int code){
        if (pwd.isEmpty()){
            ToastUtils.showMsg("当前密码为空");
            return;
        }
        Map<String,Object>map = new HashMap<>();
        map.put("phone",phone);
        map.put("pwd",pwd);
        map.put("code",code);
        m.request(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }



    @Override
    public void onNext(@NonNull BaseEntity entity) {
        v.refreshView(entity);
    }
}
